package {
	import com.greensock.TweenMax;
	
	import flash.display.MovieClip;

	public class Hud {
		
		private var _view:MovieClip;
		
		public function Hud(view:MovieClip) {
			_view = view;
		}
		
		public function set time(val:int):void {
			var times:Array = formatTime(val);
			_view.min.text = times[0];
			_view.sec.text = times[1];
		}
		
		public function animate(succes:Boolean):void {
			var c:uint;
			if(succes) c = 0x33FF99;
			else c = 0xFF3366;
			TweenMax.to(_view, .4, {delay:.6, tint:c,scaleX:2, scaleY:2});
			TweenMax.to(_view, .7, {delay:1.8, scaleX:1,scaleY:1, removeTint:true});
		}
		
		public function get view():MovieClip {
			return _view;
		}
		
		public static function formatTime(time:Number, detailLevel:uint = 1):Array {
			var intTime:int = Math.floor(time);
			if(intTime < 0) {
				intTime = 0 - intTime;	
			}
			
			var hours:int = Math.floor(intTime/ 3600);
			var minutes:int = (intTime - (hours*3600))/60;
			var seconds:int = intTime -  (hours*3600) - (minutes * 60);
			
			
			
			var minuteString:String = minutes.toString()
			var secondString:String = seconds.toString();
			
			if(minuteString.length == 1) minuteString = "0" + minuteString;
			if(secondString.length == 1) secondString = "0" + secondString;
			return [minuteString, secondString];
		}
	}
}